import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public class Visualizacao extends JPanel{

		Problema pB;
	
	 public Visualizacao(Problema p) {
	        super();
	        pB = p;
	        setLayout(new BorderLayout());
	        setBorder(BorderFactory.createLineBorder(Color.black));
	    }
	
	public void desenhaProblema(){
		
        JFrame f = new JFrame();
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        Container panel = new Visualizacao(pB);
        panel.add(new JLabel(pB.getNome(), SwingConstants.CENTER), BorderLayout.NORTH);
        f.getContentPane().add(panel, BorderLayout.CENTER);
        f.pack();
        f.setSize(300, 300);
        f.show();
		
	}
	
	 protected void paintComponent(Graphics g) {
		 /*
		 
		 for(int i = 0; i < pB.getCds().size(); i++){
			 for(int j = 0; j < pB.getCds().size(); j++){
				 g.drawLine((int)pB.getCds().get(i).getPosX(), (int)pB.getCds().get(i).getPosY(),
						 (int)pB.getCds().get(j).getPosX(), (int)pB.getCds().get(j).getPosY());
			 }
		 }*/
		 g.setColor(Color.red);
		 g.setFont(new Font(g.getFont().getFamily(), Font.BOLD, 18));
		 
		 for(int i = 0; i < Formiga.MELHOR_ROTA_GLOBAL.size()-1; i++){
			 g.drawLine((int)Formiga.MELHOR_ROTA_GLOBAL.get(i).getPosX(), (int)Formiga.MELHOR_ROTA_GLOBAL.get(i).getPosY(),
					 (int)Formiga.MELHOR_ROTA_GLOBAL.get(i+1).getPosX(), (int)Formiga.MELHOR_ROTA_GLOBAL.get(i+1).getPosY());
			 
			 if(i == Formiga.MELHOR_ROTA_GLOBAL.size()-2){
				 g.drawLine((int)Formiga.MELHOR_ROTA_GLOBAL.get(i+1).getPosX(), (int)Formiga.MELHOR_ROTA_GLOBAL.get(i+1).getPosY(),
						 (int)Formiga.MELHOR_ROTA_GLOBAL.get(0).getPosX(), (int)Formiga.MELHOR_ROTA_GLOBAL.get(0).getPosY());
			 }
		 }
		 
		 for(Cidade c : pB.getCds()){
			 g.setColor(Color.red);
			 g.setFont(new Font(g.getFont().getFamily(), Font.BOLD, g.getFont().getSize()));
			 g.drawString(String.valueOf(c.getNum()), (int)c.getPosX()-2, (int)c.getPosY()+20);
			 g.setFont(new Font(g.getFont().getFamily(), Font.PLAIN, g.getFont().getSize()));
			 g.setColor(Color.black);
			 g.fillOval((int)c.getPosX()-5, (int)c.getPosY()-4, 8, 8);
		 } 
	 }
}
